home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / Demos / Talk2boopsi.c < prev   
C/C++ Source or Header  |  1996-10-24  |  9KB  |  174 lines

  1. ;/* Talk2boopsi.c - Execute me to compile me with SAS/C 5.10b
  2. LC -b1 -cfistq -v -y -j73 Talk2boopsi.c
  3. Blink FROM LIB:c.o,Talk2boopsi.o TO Talk2boopsi LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit ;*/
  5. /*
  6. Copyright (c) 1992 Commodore-Amiga, Inc.
  7.  
  8. This example is provided in electronic form by Commodore-Amiga, Inc. for
  9. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  10. published by Addison-Wesley (ISBN 0-201-56774-1).
  11.  
  12. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  13. information on the correct usage of the techniques and operating system
  14. functions presented in these examples.  The source and executable code
  15. of these examples may only be distributed in free electronic form, via
  16. bulletin board or as part of a fully non-commercial and freely
  17. redistributable diskette.  Both the source and executable code (including
  18. comments) must be included, without modification, in any copy.  This
  19. example may not be published in printed form or distributed with any
  20. commercial product.  However, the programming techniques and support
  21. routines set forth in these examples may be used in the development
  22. of original executable software products for Commodore Amiga computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. /* This example creates a Boopsi prop gadget and integer string gadget, connecting them so they */
  32. /* update each other when the user changes their value.  The example program only initializes   */
  33. /* the gadgets and puts them on the window; it doesn't have to interact with them to make them  */
  34. /* talk to each other.                                                                          */
  35.  
  36. #include <exec/types.h>
  37. #include <utility/tagitem.h>
  38. #include <intuition/intuition.h>
  39. #include <intuition/gadgetclass.h> /* contains IDs for gadget attributes */
  40. #include <intuition/icclass.h>     /* contains ICA_MAP, ICA_TARGET       */
  41. #include <clib/exec_protos.h>
  42. #include <clib/intuition_protos.h>
  43.  
  44. #ifdef LATTICE                     /* Disable SAS/C CTRL/C handling    */
  45. int CXBRK(void) { return(0); }
  46. int chkabort(void) { return(0); }
  47. #endif
  48.  
  49. UBYTE *vers = "\0$VER: Talk2boopsi 37.1";
  50.  
  51. struct Library *IntuitionBase;
  52. struct Window *w;
  53. struct IntuiMessage *msg;
  54. struct Gadget *prop, *integer;
  55.  
  56. /* The attribute mapping lists */
  57. struct TagItem prop2intmap[] =    /* This tells the prop gadget to */
  58. {                                 /* map its PGA_Top attribute to  */
  59.     {PGA_Top,   STRINGA_LongVal}, /* STRINGA_LongVal when it       */
  60.     {TAG_END,}                    /* issues an update about the    */
  61. };                                /* change to its PGA_Top value.  */
  62.  
  63. struct TagItem int2propmap[] =    /* This tells the string gadget */
  64. {                                 /* to map its STRINGA_LongVal   */
  65.     {STRINGA_LongVal,   PGA_Top}, /* attribute to PGA_Top when it */
  66.     {TAG_END,}                    /* issues an update.            */
  67. };
  68.  
  69. #define PROPGADGET_ID       1L
  70. #define INTGADGET_ID        2L
  71. #define PROPGADGETWIDTH     10L
  72. #define PROPGADGETHEIGHT    80L
  73. #define INTGADGETHEIGHT     18L
  74. #define VISIBLE             10L
  75. #define TOTAL               100L
  76. #define INITIALVAL          25L
  77. #define MINWINDOWWIDTH      80
  78. #define MINWINDOWHEIGHT     (PROPGADGETHEIGHT + 70)
  79. #define MAXCHARS            3L
  80.  
  81.  
  82. void main(void)
  83. {
  84.     BOOL done = FALSE;
  85.  
  86.     if (IntuitionBase = OpenLibrary("intuition.library", 37L))
  87.     {                                /* Open the window--notice that the window's IDCMP port     */
  88.                                      /* does not listen for GADGETUP messages.                   */
  89.         if (w = OpenWindowTags(NULL,
  90.                  WA_Flags,       WFLG_DEPTHGADGET | WFLG_DRAGBAR |
  91.                                      WFLG_CLOSEGADGET | WFLG_SIZEGADGET,
  92.                  WA_IDCMP,       IDCMP_CLOSEWINDOW,
  93.                  WA_MinWidth,    MINWINDOWWIDTH,
  94.                  WA_MinHeight,   MINWINDOWHEIGHT,
  95.                  TAG_END))
  96.         {                                 /* Create a new propgclass object */
  97.             if (prop = (struct Gadget *)NewObject(NULL, "propgclass",
  98.                 GA_ID,     PROPGADGET_ID,        /* These are defined by gadgetclass and         */
  99.                 GA_Top,    (w->BorderTop) + 5L,  /* correspond to similarly named fields in      */
  100.                 GA_Left,   (w->BorderLeft) + 5L, /* the Gadget structure.                        */
  101.                 GA_Width,  PROPGADGETWIDTH,
  102.                 GA_Height, PROPGADGETHEIGHT,
  103.  
  104.                 ICA_MAP,      prop2intmap, /* The prop gadget's attribute map */
  105.  
  106.              /* The rest of this gadget's attributes are defined by propgclass. */
  107.                 PGA_Total,     TOTAL,          /* This is the integer range of the prop gadget.  */
  108.                 PGA_Top,       INITIALVAL,     /* The initial integer value of the prop gadget.  */
  109.  
  110.                 PGA_Visible,   VISIBLE, /* This determines how much of the prop gadget area is   */
  111.                                         /* covered by the prop gadget's knob, or how much of     */
  112.                                         /* the gadget's TOTAL range is taken up by the prop      */
  113.                                         /* gadget's knob.                                        */
  114.  
  115.                 PGA_NewLook,   TRUE,    /* Use new-look prop gadget imagery */
  116.                 TAG_END))
  117.             {                           /* create the integer string gadget.                     */
  118.                 if (integer = (struct Gadget *)NewObject(NULL, "strgclass",
  119.                     GA_ID,      INTGADGET_ID,         /* Parameters for the Gadget structure     */
  120.                     GA_Top,     (w->BorderTop) + 5L,
  121.                     GA_Left,    (w->BorderLeft) + PROPGADGETWIDTH + 10L,
  122.                     GA_Width,   MINWINDOWWIDTH -
  123.                                   (w->BorderLeft + w->BorderRight +
  124.                                   PROPGADGETWIDTH + 15L),
  125.                     GA_Height,  INTGADGETHEIGHT,
  126.  
  127.                     ICA_MAP,    int2propmap,           /* The attribute map */
  128.                     ICA_TARGET, prop,                  /* plus the target.  */
  129.  
  130.                             /* Th GA_Previous attribute is defined by gadgetclass and is used to */
  131.                             /* wedge a new gadget into a list of gadget's linked by their        */
  132.                             /* Gadget.NextGadget field.  When NewObject() creates this gadget,   */
  133.                             /* it inserts the new gadget into this list behind the GA_Previous   */
  134.                             /* gadget. This attribute is a pointer to the previous gadget        */
  135.                             /* (struct Gadget *).  This attribute cannot be used to link new     */
  136.                             /* gadgetsinto the gadget list of an open window or requester,       */
  137.                     GA_Previous, prop,  /* use AddGList() instead.                               */
  138.  
  139.                     STRINGA_LongVal,  INITIALVAL, /* These attributes are defined by strgclass.  */
  140.                     STRINGA_MaxChars, MAXCHARS,   /* The first contains the value of the         */
  141.                     TAG_END))                     /* integer string gadget. The second is the    */
  142.                                                   /* maximum number of characters the user is    */
  143.                                                   /* allowed to type into the gadget.            */
  144.                  {
  145.                     SetGadgetAttrs(prop, w, NULL, /* Because the integer string gadget did not   */
  146.                         ICA_TARGET, integer,      /* exist when this example created the prop    */
  147.                         TAG_END);                 /* gadget, it had to wait to set the           */
  148.                                                   /* ICA_Target of the prop gadget.              */
  149.  
  150.                     AddGList(w, prop, -1, -1, NULL);  /* Add the gadgets to the                  */
  151.                     RefreshGList(prop, w, NULL, -1);  /* window and display them.                */
  152.  
  153.                     while (done == FALSE)     /* Wait for the user to click */
  154.                     {                         /* the window close gadget.   */
  155.                         WaitPort((struct MsgPort *)w->UserPort);
  156.                         while (msg = (struct IntuiMessage *)
  157.                            GetMsg((struct MsgPort *)w->UserPort))
  158.                         {
  159.                             if (msg->Class == IDCMP_CLOSEWINDOW)
  160.                                 done = TRUE;
  161.                             ReplyMsg(msg);
  162.                         }
  163.                     }
  164.                     RemoveGList(w, prop, -1);
  165.                     DisposeObject(integer);
  166.                  }
  167.                 DisposeObject(prop);
  168.             }
  169.             CloseWindow(w);
  170.         }
  171.         CloseLibrary(IntuitionBase);
  172.     }
  173. }
  174.